package demo0603;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao {
    private  static  DbUntil dbUntil=new DbUntil();
    Connection connection= dbUntil.getCon();
    public  UserDao() throws SQLException, ClassNotFoundException {
    }
    public User findUser (String username,String password)throws SQLException{
        String sql="select * from users where username =? and password= ?";
        PreparedStatement preparedStatement= connection.prepareStatement(sql);

        preparedStatement.setString(1,username);
        preparedStatement.setString(2,password);
        ResultSet resultSet= preparedStatement.executeQuery();
        User user=new User();
        if (resultSet.next()){
            int id= resultSet.getInt("id");
            String name= resultSet.getNString("username");
            String pwd= resultSet.getNString("password");
            user=new User(id,username,password);

            user.setId(id);
            user.setUsernme(name);
            user.setPassword(pwd);
        }
        return user;
    }
}
